package com.ruoyi.web.controller.teacher;

import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.domain.BaseResourceInfo;
import com.ruoyi.dto.BasisPositionEquipment;
import com.ruoyi.dto.BasisPositionResourceInfo;
import com.ruoyi.dto.BasisPositionResourceInfoUser;
import com.ruoyi.service.IBaseResourceInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资源管理Controller
 * 
 * @author ruoyi
 * @date 2025-05-23
 */
@RestController
@RequestMapping("/system/info")
public class BaseResourceInfoController extends BaseController
{
    @Autowired
    private IBaseResourceInfoService baseResourceInfoService;

    /**
     * 查询资源管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BaseResourceInfo baseResourceInfo)
    {
        startPage();
        List<BaseResourceInfo> list = baseResourceInfoService.selectBaseResourceInfoList(baseResourceInfo);
        return getDataTable(list);
    }

    /**
     * 导出资源管理列表
     */
    @Log(title = "资源管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseResourceInfo baseResourceInfo)
    {
        List<BaseResourceInfo> list = baseResourceInfoService.selectBaseResourceInfoList(baseResourceInfo);
        ExcelUtil<BaseResourceInfo> util = new ExcelUtil<BaseResourceInfo>(BaseResourceInfo.class);
        util.exportExcel(response, list, "资源管理数据");
    }

    /**
     * 获取资源管理详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baseResourceInfoService.selectBaseResourceInfoById(id));
    }

    /**
     * 新增资源管理
     */
    @Log(title = "资源管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseResourceInfo baseResourceInfo)
    {
        UUID uuid = UUID.randomUUID();
        baseResourceInfo.setUuid(uuid.toString());
        if("超短波天线".equals(baseResourceInfo.getType()) || "微波天线".equals(baseResourceInfo.getType()) || "卫星天线".equals(baseResourceInfo.getType())){
            baseResourceInfo.setIs_tx("1");
        }else{
            baseResourceInfo.setIs_tx("2");
        }
        return toAjax(baseResourceInfoService.insertBaseResourceInfo(baseResourceInfo));
    }

    /**
     * 修改资源管理
     */
    @Log(title = "资源管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseResourceInfo baseResourceInfo)
    {
        if("超短波天线".equals(baseResourceInfo.getType()) || "微波天线".equals(baseResourceInfo.getType()) || "卫星天线".equals(baseResourceInfo.getType())){
            baseResourceInfo.setIs_tx("1");
        }else{
            baseResourceInfo.setIs_tx("2");
        }
        return toAjax(baseResourceInfoService.updateBaseResourceInfo(baseResourceInfo));
    }

    /**
     * 删除资源管理
     */
    @Log(title = "资源管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseResourceInfoService.deleteBaseResourceInfoByIds(ids));
    }



    @PostMapping("/addBasisPositionResourceInfo")
    public AjaxResult addBasisPositionResourceInfo(@RequestBody BasisPositionResourceInfo basisPositionResourceInfo)
    {
        return toAjax(baseResourceInfoService.addBasisPositionResourceInfo(basisPositionResourceInfo));
    }

    @GetMapping("/findByLoadingIdAndPositionIdFromResource")
    public AjaxResult findByLoadingIdAndPositionIdFromResource(String loadingId,Integer positionId)
    {
        return success(baseResourceInfoService.findByLoadingIdAndPositionIdFromResource(loadingId, positionId));
    }


    @GetMapping("/findByLoadingIdFromResource")
    public AjaxResult findByLoadingIdFromResource(String loadingId)
    {
        return success(baseResourceInfoService.findByLoadingIdFromResource(loadingId));
    }


    @GetMapping("/delBasisPositionResourceInfo")
    public AjaxResult delBasisPositionResourceInfo(String loadingId,Integer positionId,Integer resourceId)
    {
        return success(baseResourceInfoService.delBasisPositionResourceInfo(loadingId, positionId,resourceId));
    }


    @GetMapping("/delBasisPositionResourceInfoAll")
    public AjaxResult delBasisPositionResourceInfoAll(String loadingId,Integer positionId)
    {
        return success(baseResourceInfoService.delBasisPositionResourceInfoAll(loadingId, positionId));
    }

    @GetMapping("/findByResourceIdAndLoading")
    public AjaxResult findByResourceIdAndLoading(Integer resourceId,String loadingId)
    {
        return success(baseResourceInfoService.findByResourceIdAndLoading(resourceId, loadingId));
    }

}
